package com.zr.subclass.controller;

import com.zr.subclass.pojo.SubClassAddVo;
import com.zr.subclass.pojo.SubClassSelectVo;

import com.zr.subclass.pojo.SubClassStatusVo;
import com.zr.subclass.pojo.SubClassUpdateVo;
import com.zr.subclass.service.SubClassService;
import com.zr.util.AllRecords;
import com.zr.util.ResultBuildVo;
import com.zr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * Created by 86151 on 2019/6/14.
 */
@RestController
@CrossOrigin
public class SubClassController {
    @Autowired
    private SubClassService subClassService;

    @PostMapping("subClass/add")
    public ResultVo addPlanClass(@RequestBody @Valid SubClassAddVo subClassAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage(),"500");
        }
        return subClassService.addSubClass(subClassAddVo);
    }

    /**
     * 修改接口
     * @param subClassUpdateVo
     * @param bindingResult
     * @return
     */
    @PostMapping("subClass/update")
    public ResultVo updatePlant(@RequestBody @Valid SubClassUpdateVo subClassUpdateVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage(),"500");
        }
        return subClassService.updatePlant(subClassUpdateVo);
    }

    /**
     * 修改状态接口
     * @param subClassStatusVo
     * @param bindingResult
     * @return
     */
    @PostMapping("subClass/updateStatus")
    public ResultVo updateStatus(@RequestBody @Valid SubClassStatusVo subClassStatusVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage(),"500");
        }
        return subClassService.updateStatus(subClassStatusVo);
    }

    /**
     * 查看
     */
    @RequestMapping("queryPlanClassById")
    public ResultVo queryPlanClassById(@RequestParam("id")Integer id){

        return subClassService.querySubClassById(id);
    }
    /**
     * 分页查询
     */
    @PostMapping("subClass/queryPage")
    public ResultVo<AllRecords> queryPage(@RequestBody SubClassSelectVo subClassSelectVo){

        return subClassService.queryPage(subClassSelectVo);
    }

//    /**
//     * 启用禁用下拉框
//     */
//    @PostMapping("metadata/getPullDownList")
//    public ResultVo<List<XiaLaVo>> queryXiaLa(@RequestBody List<String> status){
//        List<XiaLaVo> xiaLaVoList = new ArrayList<>();
//        for (int i = 0; i< StatusEnum.values().length; i++){
//            XiaLaVo xiaLaVo = new XiaLaVo();
//            xiaLaVo.setValue(i);
//            xiaLaVo.setLabel(StatusEnum.getName(i));
//            xiaLaVoList.add(xiaLaVo);
//        }
//        return ResultBuildVo.success(xiaLaVoList);
//    }
}
